package com.xinfu.newproject.presenter;


import com.xinfu.newproject.bean.pay.PayBean;
import com.xinfu.newproject.bean.pay.PayBody;
import com.xinfu.newproject.bean.pay.bean.PayCostBean;
import com.xinfu.newproject.bean.pay.body.PayCostBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.PayModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class PayPresenter {
    private IView.IPayView mPayView;
    private IView.IPayPropertyView mPayPropertyView;


    private PayModel mPayModel;

    public PayPresenter(IView.IPayView iPayView) {
        this.mPayView = iPayView;
        mPayModel = new PayModel();
    }

    public PayPresenter(IView.IPayPropertyView iPayPropertyView) {
        this.mPayPropertyView = iPayPropertyView;
        mPayModel = new PayModel();
    }



    /**
     * 报修支付
     */
    public void pay() {

        mPayView.showProgress();

        PayBody payBody = new PayBody(mPayView.header(), mPayView.mobile(), mPayView.payType(), mPayView.billType(), mPayView.roomId(), mPayView.payFee(), mPayView.repairOrder(), mPayView.userId());

        mPayModel.pay(payBody, new MyCallBack<PayBean>() {
            @Override
            public void onSuccess(PayBean payBean) {
                mPayView.hideProgress();
                if (payBean.isSuccess()) {
                    mPayView.getMsg(payBean);
                } else {
                    mPayView.showToast(payBean.getMessage());
                }
//                mPayView.showToast(payBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {
                mPayView.hideProgress();
                mPayView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mPayView.closeDispose(disposable);
            }
        });


    }


    /**
     * 物业支付
     */
    public void payCost() {

        mPayPropertyView.showProgress();

        PayCostBody payCostBody = new PayCostBody(mPayPropertyView.header()
                , mPayPropertyView.billType()
                , mPayPropertyView.billids()
                , mPayPropertyView.payFee()
                , mPayPropertyView.name()
                , mPayPropertyView.mobile()
                , mPayPropertyView.roomId()
                , mPayPropertyView.userId()
                , mPayPropertyView.payType()
                , mPayPropertyView.invoiceName()
                , mPayPropertyView.invoiceAddress()
                , mPayPropertyView.invoiceMobile()
                , mPayPropertyView.invoiceEmail()
                , mPayPropertyView.invoiceAccount()
                , mPayPropertyView.invoiceEin());

        mPayModel.payCost(payCostBody, new MyCallBack<PayCostBean>() {
            @Override
            public void onSuccess(PayCostBean payCostBean) {
                mPayPropertyView.hideProgress();
                if (payCostBean.isSuccess()) {
                    mPayPropertyView.getMsg(payCostBean);
                } else {
                    mPayPropertyView.showToast(payCostBean.getMessage());
                }
//                mPayView.showToast(payBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {
                mPayPropertyView.hideProgress();
                mPayPropertyView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mPayPropertyView.closeDispose(disposable);
            }
        });


    }


}
